var imgs = [];
var imgtext = [];

var swiper = 	new Swiper('.swiper-container', {
			pagination: '.swiper-pagination',
			paginationClickable: true,
			loop: true,
			autoplay: 3000,
			autoplayDisableOnInteraction: false,
			observer:true,
			observeParents:true,
			watchActiveIndex:true,
	});
		
		
var app = angular.module("suixia",[]);
app.controller("indexController",function($scope,$http){
	$http.get(apiRoot+"?m=Home&c=article&a=scroll&taid=1")
	.then(function success(res){
		$scope.images = res.data.home;
		$scope.webRoot = webRoot;
	})
	.then(function getData(){
		swiper.reInit();
	})
})


document.addEventListener('plusready',function(){
	plus.nativeUI.closeWaiting();
	//轮播图
//	$.ajax({ 
//		type:"get",  
//		url: apiRoot+'?m=Home&c=article&a=scroll', 
//		data : {
//			taid : 1
//		},
//		dataType :'json',
//		success : function(data){
//			if(data.home){
//				$.each(data.home, function(index , value){ 
//					imgtext.push(value.name);
//					imgs.push({"i":index,'img':value.adfile.replace('/uploads', webRoot+'/uploads')});
//				}); 
//				slider.init(); 
////				var zhuye = '';
////				zhuye = '<div class="mui-slider-item mui-slider-item-duplicate"><a href="#"><img style="height:180px;" src="'+ webRoot + data.home[(data.home).length-1].adfile +'"/><p class="mui-slider-title">'+ data.home[(data.home).length-1].name +'</p></a></div>';
////				$.each(data.home, function(index , value){ 
////					zhuye +='<div class="mui-slider-item"><a href="#"><img style="height:180px;" src="'+ webRoot + value.adfile +'" /><p class="mui-slider-title">'+ value.name +'</p></a></div>'; 
////				});     
////				zhuye += '<div class="mui-slider-item mui-slider-item-duplicate"><a href="#"><img style="height:180px;" src="'+ webRoot + data.home[0].adfile +'"/><p class="mui-slider-title">'+ data.home[0].name +'</p></a></div>'; 
////				$('.banner1').html(zhuye);
//			}
//			if(data.wei){
//				$('.bot-img').show();
//				if(data.wei.gourl){
//					$('.bot-img').on('tap', function(){
//						plus.runtime.openURL(data.wei.gourl);
//					});
//				}
//				$('.bot-img img').attr('src', webRoot + data.wei.adfile);
//			}
//		},
//		error : function(e){
//			console.log(JSON.stringify(e));
//		}
//	})
	//最新资讯
	$.ajax({
		type : "get",
		url : apiRoot+"?m=home&c=article&a=tuiNews",
		dataType :'json',
		success : function(data){
			if(data){
				var list = '';
				$.each(data, function(k,v) {
//					console.log(JSON.stringify(v));
					list += '<div class="mui-table-view background table-view-cell home-list" data-id="'+v.id+'">'+
								'<div>'+
									'<img src="'+webRoot+v.litpic+'" alt="" />'+
								'</div>'+
								'<div class="">'+
									'<li class="font-17">'+(v.title).substring(0,10)+'...</li>'+
									'<li class="mui-ellipsis-2 font-12">'+(v.description)+'</li>'+
								'</div>'+
							'</div>';
				});
				$('.newsList').html(list);
				$('.home-list').on('click',function(){
					var id = $(this).attr('data-id');
					goNewPage('jk-new.html',{aid:id});
				})
			}
		},
		error : function(e){
			console.log(JSON.stringify(e));
			errortoast();
		}
	});
	$('.ancient').on('tap', function(){
		goNewPage('home-old-method-list.html');
	})
},false)